博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Umbraco XSLT
阅读量:7238 次
发布时间:2019-06-29

本文共 4281 字,大约阅读时间需要 14 分钟。

Supported by

I will introduce XSLT around Umbraco to help you understand it quickly. I will appreciate if you have any feedbacks on the article.

The article includes following points.

  1. What are we building?
  2. What’s the XML that will be transformed by the XSLT files in Umbraco?
  3. Commonly used attributes in Umbaco xslt.
  4. Commonly used operators in xsl
  5. Commonly used xsl functions
  6. What are the common tasks in coding with XSLT in Umbraco?

What are we building

We are building templates to transform xml datasource to html. It is powered by XSL(Extensible Stylesheet Language).

XSLT is heavily used in Umbraco. You can see it in building menus, news list, image gallery or any forms of representation in html.

You can add XSLT in Developers->XSLT Files in Umbraco backoffice, and then use  XSLT script by Umbraco macro.

Umbraco has shipped with XSLT files for most requirement that can be used with little modification. Those files are helpful to you to understand the XSLT in Umbraco as well.

What’s the XML that will be transformed by the XSLT files in Umbraco

  1. umbraco.config in App_Data.
  2. collection returned by xslt extension functions. It is recommended to define the returned datatype as System.Xml.XPath.XPathNodeIterator.

Common used attributes in Umbraco xslt

@id: used for computing the url for the content. Commonly used as following.

<a href=’umbraco.library:NiceUrl(@id)’ />

@isDoc: used for indicating is the current node is just content or associated with template. If false, indicating it is content associated with template. Commonly used in generating menus.

<xsl:for-each select=”$currentPage/*[not(@isDoc)]”>

@level: used for indicating the level number of current node in the tree nodes, starting with 1. Commonly used in generating menus.

<xsl:for-each select=”$currentPage/*[not(@isDoc) and @level = 2]”>

@nodeName: used for indicating the name of the node. Commonly used in generating menus.

<xsl:for-each select=”$currentPage/*[not(@isDoc) and @level = 2]”>

<li><xsl:value-of select=”@nodeName”/></li>

</xsl:for-each>

 

Commonly used operators in xsl

plus +
minus -
multiply *
division div
mod mod
and and
or or
not not()

 

Commonly used functions in xsl

position(): return the index of the current node in for-each

current(): return the current node

name(): return the name of the current node or the first node in the specified node set. It is heavily used in the xslt for related links.

<xsl:for-each select=”$currentPage/*[name()=@propertyAlias]/links/link”>

</xsl:for-each>

count(“expression”): return the number of the elements in the expression

Please refer to and for more functions.

What’s the common task in coding with XSLT in Umbraco

  1. Iterating the nodes in umbraco.config file
  2. Filtering the nodes in umbraco.config file
  3. Working with umbraco xslt extension functions

Iterating the nodes in umbraco.config file

 

"currentPage” is the parameter in the template. The value is supplied by umbraco system when the template is invoked by umbraco system. It represents the current node where the xslt macro exists.

Let’s say, we have the content  structure in the screenshot above. If we put the xslt in the template of NewsPage, $currentPage represents the “NewsPage” node. So to iterate the child nodes in NewsPage, we will write the following code.

Note: “NewsItem” is the node name of the news.

Or

Please refer to “” section in w3school for more details for selecting nodes.

 

Filtering the nodes in umbraco.config file

You can use xpath predicates to filter the nodes.

Or

Please refer to “” section in w3school for more details for filtering nodes.

Working with umbraco xslt extension functions

Umbraco has shipped with rich set of xslt extension functions.

To apply the xslt extension functions, we must declare the xmlns for the xslt library.

Then invoke the functions as following.

We can create our own xslt extension functions to embrace specific business as well.

 

The skeleton of the article is completed. I will improve the content in the common tasks section in the coming up days.

Reference

 

 

Supported by

转载于:https://www.cnblogs.com/czy/archive/2012/07/23/2605770.html

你可能感兴趣的文章
接口回调是什么
查看>>
java开篇之基础
查看>>
基于web-msg-sender进行消息推送
查看>>
代理服务器(3)
查看>>
《编写可维护的 JavaScript》读书笔记第20章:组装到一起
查看>>
升级 XCODE7后的问题备忘
查看>>
内存跟踪工具, 需要cygwin trackmem1.sh
查看>>
php正则匹配重写html图片img路径
查看>>
样条表示---Bezier曲面
查看>>
关于码代码的那点破事
查看>>
sequelize update 原生sql 没有返回值
查看>>
根据手机类型调转到应用吧还是appstore下载应用
查看>>
听阿里巴巴JVM工程师为你分析常见Java故障案例
查看>>
Sphinx reStructuredText 的安装
查看>>
日本程序员是这样吗
查看>>
JavaScript与C++对象绑定原理及效率分析
查看>>
大数据时代的IT架构设计
查看>>
Custom Tableviews
查看>>
java 开源 cms FreeCMS1.6发布
查看>>
事件库之Libev(一)
查看>>